package kr.hkit.androidcomplete01.chapter06;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class SetParameterEx extends Activity {

	Button mLeft;
	Button mRight;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setparameter);

		mLeft = (Button) findViewById(R.id.btnleft);
		mRight = (Button) findViewById(R.id.btnright);
	}

	public void mOnClick(View v) {
		switch (v.getId()) {
		case R.id.btnleft:
			setParam(3, 1);
			break;

		case R.id.btnright:
			setParam(1, 3);
			break;
		}
		
		/*mLeft.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				setParam(3, 1);
			}
		});
		
		mRight.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				setParam(1, 3);
			}
		});*/
	}

	protected void setParam(int left, int right) {
		LinearLayout.LayoutParams lparam = (LinearLayout.LayoutParams) mLeft.getLayoutParams();
		lparam.weight = left;
		mLeft.setLayoutParams(lparam);

		LinearLayout.LayoutParams rparam = (LinearLayout.LayoutParams) mRight.getLayoutParams();
		rparam.weight = right;
		mRight.setLayoutParams(rparam);

	}
}
